<?php

// 本类由系统自动生成，仅供测试用途
class PersonalCenterAction extends Action
{
    public function index()
    {
        $users = M('users');
        $whereUsers['id'] = session('uid');
        $oneUsers = $users->where($whereUsers)->find();
        $userInfo['email'] = $oneUsers['email'];
        $userInfo['tel'] = $oneUsers['phone_num'];
        $userInfo['year'] = explode('.',$oneUsers['birthday'])[0];
        $userInfo['month'] = explode('.',$oneUsers['birthday'])[1];
        $userInfo['day'] = explode('.',$oneUsers['birthday'])[2];
        $userInfo['trueName'] = $oneUsers['sh_name'];
        $userInfo['phone'] = $oneUsers['phone'];
        $userInfo['postcode'] = $oneUsers['postcode'];
        $userInfo['address2'] = $oneUsers['address2'];
        $userInfo['uid'] = session('uid');
        $this->assign('userInfo',$userInfo);
        $this->display('personalCenter');
    }

    public function change_email()
    {
        $data['email'] = I('email');
        $where['id'] = session('uid');
        $users = M('users');
        $one = $users->where($where)->save($data);
        if($one){
            $this->ajaxReturn('','',1);
        }else{
            $this->ajaxReturn('','',0);
        }
    }
    public function change_tel()
    {
        $data['phone_num'] = I('tel');
        $where['id'] = session('uid');
        $users = M('users');
        $one = $users->where($where)->save($data);
        if($one){
            $this->ajaxReturn('','',1);
        }else{
            $this->ajaxReturn('','',0);
        }
    }
    public function change_info(){
        $data['birthday'] = I('birth_year').'.'.I('birth_month').'.'.I('birth_day');
        $data['sh_name']= I('trueName');
        $data['address2'] = I('address2');
        $data['postcode'] = I('postcode');
        $data['phone'] = I('phone');
        $users = M('users');
        $where['id'] = session('uid');
        $one = $users->where($where)->save($data);
        if($one){
            $this->ajaxReturn('','',1);
        }else{
            $this->ajaxReturn('','',0);
        }
    }
}